package org.weasel.base;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.weasel.controllers.ApplicationController;
import org.weasel.controllers.PreferenceController;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

    public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        super(configurer);
    }

    @Override
	public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
        return new ApplicationActionBarAdvisor(configurer);
    }
    
    @Override
	public void preWindowOpen() {
        IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); 
        configurer.setShowCoolBar(true);
        configurer.setShowStatusLine(false);
        configurer.setTitle("Weasel - Agile Project Planner");
//        set defaults
    	PreferenceController.instance().initDefaults();
        //create an initial instance of the ApplicationController
        ApplicationController.instance();
    }
    
    @Override
    public void postWindowOpen() {
    	//maximizes the window after the shell has been loaded
    	IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
    	boolean wantMaximized = PreferenceController.instance().getPrefStore().getBoolean(PreferenceController.MAXIMIZED_PREFERENCE);
    	configurer.getWindow().getShell().setMaximized(wantMaximized);
    }
    
    @Override
    public boolean preWindowShellClose() {
    	return ApplicationController.instance().programCloseClicked();
    }
    
    @Override
    public IStatus saveState(IMemento memento) {
    	return null;
    }
}
